package com.corhyfar.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.corhyfar.beans.DepartamentoDTO;
import com.corhyfar.dao.DepartamentoDao;
import com.corhyfar.util.SQLConnection;

public class DepartamentoDaoImpl implements DepartamentoDao {

	Connection cn = null;
	PreparedStatement ps = null;
	ResultSet rs = null;

	@Override
	public List<DepartamentoDTO> listarDepartamentos() {
		List<DepartamentoDTO> lista = new ArrayList<DepartamentoDTO>();
		try {
			cn = new SQLConnection().GetConnection();
			String sql = "select * from DEPARTAMENTO";
			ps = cn.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {

				lista.add(new DepartamentoDTO(rs.getInt(0), rs.getString(1), rs
						.getInt(2)));

			}
			ps.close();
			cn.close();
		} catch (SQLException e) {
			e.printStackTrace();

		}
		return lista;

	}

}
